package org.hgvc.webapp.ets.spring.service;

import java.util.Date;
import java.util.List;

import org.hgvc.webapp.ets.bo.Complaint;
import org.hgvc.webapp.ets.constant.CommonConstant;
import org.hgvc.webapp.ets.constant.ComplaintConstant;
import org.hgvc.webapp.ets.spring.dao.ComplaintHbmDao;
import org.jocsb.base.bo.User;
import org.jocsb.base.exception.BaseException;
import org.jocsb.base.util.SpringUtils;


public class ComplaintServiceImpl implements ComplaintService {

	private ComplaintHbmDao dao;

	public void setDao(ComplaintHbmDao dao) {
		this.dao = dao;
	}
	
	public List<Complaint> getComplaintListByRefIdType(String refId,String type)throws BaseException{
		try{
			return dao.getComplaintListByRefIdType(refId,type);
		}catch(Exception be){
			be.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.list.complaint", new Object[]{}));
		}
	}
	
	public List<Complaint> getComplaintList()throws BaseException{
		try{
			return dao.getComplaintListByStatus(ComplaintConstant.COMPLAINT_STATUS_PENDING);
		}catch(Exception ex){
			ex.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.list.complaint", new Object[]{}));
		}
	}
	
	public void createComplaint(Complaint complaint,User createdUser)throws BaseException{
		try{
			complaint.setStatus(ComplaintConstant.COMPLAINT_STATUS_PENDING);
			complaint.setCreatedBy(createdUser);
			complaint.setCreatedDate(new Date());
			complaint.setIsDeleted(CommonConstant.NOT_DELETED);
			dao.save(complaint);
		}catch(Exception be){
			be.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.submit.complaint", new Object[]{}));
		}
	}
	
	public void replyComplaint(Complaint complaint,User user)throws BaseException{
		try{
			complaint.setStatus(ComplaintConstant.COMPLAINT_STATUS_ACK);
			complaint.setModifiedBy(user);
			complaint.setModifiedDate(new Date());
			dao.update(complaint);
		}catch(Exception be){
			be.printStackTrace();
			throw new BaseException(SpringUtils.getMessage("error.reply.complaint", new Object[]{}));
		}
	}
}
